class TreeNode:
    def __init__(self,val=0,left=None,right=None):
        self.val=val
        self.left=left
        self.right=right

root=TreeNode(1)
# l_1=root.left=TreeNode(2,None,None)
# r_1=root.right=TreeNode(3,None,None)
# l_2=l_1.left=TreeNode(4)
# r_2=l_1.right=TreeNode(5)
# l_3=l_2.left=TreeNode(6)
# r_3=l_2.right=TreeNode(7)
def dfs(root,path,ans):
    if not root:
        return None
    if not root.left and not root.right:
        #叶子节点
        path+=str(root.val)
        ans.append(path)
        # print(path)
        return None

    path+=str(root.val)+"->"
    # print(path)
    dfs(root.left,path,ans)
    # path=path[:len(path)]
    dfs(root.right,path,ans)
    # path=path[:len(path)]
def binaryTreePaths(root):
    #这里的path是路径
    path=""
    #用来存放最终结果的列表
    ans=[]
    dfs(root,path,ans)
    return ans
print(binaryTreePaths(root))